<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;


/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class CustomerguanliController extends AdminController {
    
	//客户管理
	public function customer_guanli(){
        $map = array();
        $map  = array('status' => 1);
        if(isset($_GET['name'])){
            $map['name']    =   array('like', '%'.(string)I('name').'%');
        }
		
		$lists = $this->lists('Customer_info',$map,'uid asc');
		//$lists  = D('Customer_info')->where($map)->order('uid asc')->select();//查询语句
    	$this->assign('customerguanli',$lists);
	 
	    $this->display();
	}
	
	//客户录入
	public function customer_luru($name='',$nature='',$address='',$area='',$province='',$city='',$mobile='',$contactname='',$tellphone='',$email='',$position='',$qq='',$faxnumber='',$introduction='',$certificate_path='',$status=''){
        if(IS_POST){
			if($_POST['name']!=""&&$_POST['nature']!=""&&$_POST['address']!=""&&$_POST['area']!=""&&$_POST['province']!=""&&$_POST['city']!=""&&$_POST['contactname']!=""&&$_POST['tellphone']!=""&&$_POST['email']!=""){

            $customer_info=array('name'=>$name,'nature'=>$nature,'address'=>$address,'area'=>$area,'province'=>$province,'city'=>$city,'mobile'=>$mobile,'contactname'=>$contactname,'tellphone'=>$tellphone,'email'=>$email,'position'=>$position,'qq'=>$qq,'faxnumber'=>$faxnumber,'introduction'=>$introduction,'certicate_path'=>$certificate_path,'status'=>1);
            if(!M('Customer_info')->add($customer_info)){
                echo "<script>alert('信息录入失败！');</script>";
            }else{
                echo "<script>alert('信息录入成功！');</script>";
            }
		   }else{
		       echo "<script>alert('请将信息输入完整,带红色标记的选项为必填项，请仔细检查');</script>";
		   }

        }
        
	 
	    $this->display();
	}

	public function customer_bianji($uid=0){
        
         if(IS_POST){
            $customer_info = D('Customer_info');
            $data = $customer_info->create();
            //var_dump($data);exit;
            if($data){
                if($customer_info->save()!== false){
                    
                    $this->success('更新成功',U('customerguanli/customer_guanli'));
                } else {
                    $this->error('更新失败');
                }
            } else {
                $this->error($customer_info->getError());
            }
		
		 }else {
            $info = array();
            /* 获取数据 */
            $info = M('Customer_info')->find($uid);
            $customer = M('Customer_info')->field(true)->select();
            $customer = D('Common/Tree')->toFormatTree($customer);

           
            //$this->assign('Menus', $customer);
            //if(false === $info){
             //   $this->error('获取后台信息错误');
            //}
           $this->assign('info', $info);
            
            $this->display();
       }
		
	
	}
	//删除
	 public function del(){
        $id = array_unique((array)I('uid',0));

        if ( empty($id) ) {
            $this->error('请选择要操作的数据!');
        }

        $map = array('uid' => array('in', $id) );
        if(M('Customer_info')->where($map)->delete()){
            S('DB_CONFIG_DATA',null);
            //记录行为
            action_log('update_config','Customer_info',$id,UID);
            $this->success('删除成功！');
        } else {
            $this->error('删除失败失败！');
        }
    }


}




?>